﻿#pragma once
#include <cassert>

#ifndef ARD_PREUDOCODE_H
#define ARD_PREUDOCODE_H

#define BIT(n)
#define TODO(e)					Abort(e<<" Must todo ->"<<__func__<<std::dec<<":"<<__LINE__)
#define WARNTODO(e)				LogW(__func__<<" Need todo,line:"<<std::dec<<__LINE__<<"->"<<e)
#define UNREACHABLED()			Abort("can\'t reach here ->"<<__func__<<std::dec<<":"<<__LINE__) 

#define UsingAArch32(x)			(x->rw == 1)
#define EQ(x)					(x->z == 1)
#define CS(x)					(x->c == 1)
#define MI(x)					(x->n == 1)
#define VS(x)					(x->v == 1)
#define NE(x)					!EQ(x)
#define CC(x)					!CS(x)
#define PL(x)					!MI(x)
#define VC(x)					!VS(x)
#define	HI(x)					(CS(x)&&NE(x))
#define GE(x)					(x->n == x->v)
#define	GT(x)					(GE(x)&&NE(x))
#define LS(x)					!HI(x)
#define LT(x)					!GE(x)
#define	LE(x)					!GT(x)

#define EL(x)					(x->el)
#define SP(x)					(x->sp)
//将宽度为n的有符号数据扩展为m的数据类型宽度
#define SignExtend(m,x,n)		{struct AA{int64_t a:n;};struct AA a={.a=x};m=a.a;}

//ARMv8.2引入了Statistical Profiling Extension(SPE)，它提供了一种非侵入性的软件和硬件采样方法，可以对指令集架构定义的架构指令或uop进行采样分析。
//SPE通过硬件采集CPU执行过程中发生的event，根据软件设置的采样间隔对指令进行采样，由硬件产生SPE的record packet并将packet写入外部内存。SPE采样的指令地址信息是非常精确的，不会漂移。而且采样记录的开销较小，因而采样率可以设置的很高
#define HAS_SPE_FDS				false

#define HSA_SECURE_ONLY			false
//EL 0,1必须支持
#define EL0						0
#define EL1						1
#define EL2						2
#define EL3						3
#define HAS_AA64EL0				true
#define HAS_AA32EL0				true
#define HAS_AA64EL1				true
#define HAS_AA32EL1				true
#define HAS_AA64EL2				false
#define HAS_AA32EL2				false
#define HAS_AA64EL3				false
#define HAS_AA32EL3				false
#define HaveEL(x)				(x<2)
#define HaveSecureEL2Ext()		false	
#define ELUsingAArch32(el)		_ELStateUsingAArch32(el, _IsSecureBelowEL3())
#define HaveAArch32EL(el)		(el<2)
#define HaveAArch64()			(HAS_AA64EL0 || HAS_AA64EL1 || HAS_AA64EL2 || HAS_AA64EL3)
#define HaveAArch32()			(HAS_AA32EL0)
#define BranchNotTaken()		if(HAS_SPE_FDS){LogW("SPE FDS Not Impl...");}
#define IsSecureEL2Enabled()    false
#define EL2Enabled(scr)			(HaveEL(EL2)&&(!HaveEL(EL3)||SCREL3_NS(scr)|| IsSecureEL2Enabled()))
#define HaveVirtHostExt()		false
#define HaveBRBExt()			false
#define Hint_Branch(type)
#define HavePACExt()			false // Returns TRUE if support for the PAC extension is implemented, FALSE otherwise						
#define	IsInHost(el)			_ELIsInHost(el)
	
#define HaveStatisticalProfiling()	false

#define HaveGCS()					false
#define HaveFeatHCX()				false
#define HaveTME()					false
#define HaveRME()					false
#define HaveSME()					false
#define HaveLSE2Ext()				false
#define HaveNV2Ext()				false
#define HaveMTE2Ext()				false
#define HaveMPAMv0p1Ext()			false
#define HaveMPAMv1p1Ext()			false
#define Have128BitDescriptorExt()	false
#define HaveSVE()					false
#define HaveE0PDExt()				false
#define HaveHPDExt()				false
#define HaveMTE4Ext()				false
#define HaveE0PDExt()				false
#define HaveFEATASID2()				false
#define HaveS1POE()					false


#define IsTCR2EL1Enabled()			false
#define IsAligned(x,align)			x == (align * (x / align))   //x%align

#define SecureOnlyImplementation	true
#define SharedSMCUImplementation	false
#define MPAMSM_EL1_Label_Implementation	false
		

#define CurrentSecurityState(el)	_SecurityStateAtEL(el)
#define AArch64GetVARange(a)		GetBitBool(a,55)?VARange::VARange_UPPER:VARange::VARange_LOWER
#define IsFault(e)					e.statuscode!=Fault::Fault_None
#define HasUnprivileged(regime)		(regime == Regime::Regime_EL10 || regime == Regime::Regime_EL20||regime == Regime::Regime_EL30)
#define AArch64HaveS1TG(tg)			(tg==TGx::TGx_4KB) //默认只有使用TGx::TGx_4KB

//////////////////////////////////////////////
#define BitType(n)				typedef struct { uint64_t a : 6; } BitVar##n;
BitType(6)
#endif // !ARD_PREUDOCODE_H
